package com.ima.controller;

import com.ima.model.Persion;
import com.ima.repository.PersionRepository;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/perison")
public class PersionController {

    @Resource
//    private PersionService persionService;
    private PersionRepository persionRepository;

    @RequestMapping("/index")
    public String index(){
        return "index";

    }

    @RequestMapping("/search")
    public @ResponseBody String search(String userName){
        Persion persion = new Persion();
        persion.setId("4");
        //persion.setUserName("abc4");
        persion.setUserSex("4");
        //Persion persion1 = persionRepository.save(persion);
//        System.out.println(persion1.toString());
        persion.setUserName("abc223");
        String sql = "update t_persion set userName = ? where id = '2'";
        String sql2 = "select * from Persion LIMIT 0,2";
//        Persion persion1 = persionRepository.update(persion);
        persionRepository.delete(persion);
        Map<String,Object> map = new HashMap<>();
        map.put("userName", "abc223");
//        persionRepository.updateNativeSql("update t_persion set userName =:userName where id = '4'", map);
//        return persion1.toString();
//        persionRepository.testUpdate("55555555");
//        persionRepository.testUpdate("8888");
        return "success!";
    }

}
